package com.qf.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAccountTraceMapper;
import com.qf.pojo.DtsAccountTrace;
import com.qf.service.DtsAccountTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DtsAccountTraceServiceImpl implements DtsAccountTraceService {

    @Autowired
    DtsAccountTraceMapper accountTraceMapper;

    @Override
    public IPage<DtsAccountTrace> findPage(Integer page, Integer limit, String username, String mobile, List<String> statusArray, String sort, String order) {
        IPage<DtsAccountTrace> iPage = new Page<>(page,limit);

        QueryWrapper<DtsAccountTrace> wrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(username)){
            wrapper.like("username",username);
        }

        if(!StringUtils.isEmpty(mobile)){
            wrapper.eq("mobile",mobile);
        }

        if(statusArray != null&& statusArray.size()>0){
            wrapper.in("status",statusArray);
        }

        if(order.equalsIgnoreCase("asc")){
            wrapper.orderByAsc(sort);
        }else {
            wrapper.orderByDesc(sort);
        }

        iPage = accountTraceMapper.selectPage(iPage,wrapper);
        return iPage;
    }
}
